import pygame
import sys
import time


#Iniciar pygame
pygame.init()

#Configurar la ventana
ancho = 711
alto = 529
ventana = pygame.display.set_mode((ancho, alto))
pygame.display.set_caption('Conster`s game')

#Variables
rojo = (255,0,0)
estado = 0
azul = (0,255,255)
verde = (0,255,0)
amarillo = (255,255,0)
naranja = (210,105,30)
#Musica
shot = pygame.mixer.music.load("disparo.mp3")

#Portada
tioloco = pygame.image.load("img/tioloco.jpg")
x,y = 0,0
ventana.blit(tioloco, (x,y))

#Texto
fuente = pygame.font.SysFont(None, 48)
texto = fuente.render("The walking dead", True, amarillo)
textoRect = texto.get_rect()
textoRect.centerx = ventana.get_rect().centerx
textoRect.centerx = ventana.get_rect().centery
ventana.blit(texto, (200,170))

#Texto2
fuente2 = pygame.font.SysFont(None, 35)
texto2 = fuente2.render("<Pulsa cualquier tecla para comenzar>", True, rojo)
ventana.blit(texto2, (135,470))

#Controles
controles = fuente2.render("Controles:", True, azul)
ventana.blit(controles, (30,220))

humano = fuente2.render("Humano", True, verde)
ventana.blit(humano, (140,280))

w = fuente.render("W", True, verde)
ventana.blit(w, (170,330))

s = fuente.render("S", True, verde)
ventana.blit(s, (174,380))

a = fuente.render("A", True, verde)
ventana.blit(a, (120,380))

d = fuente.render("D", True, verde)
ventana.blit(d, (228,380))

zzombie = fuente2.render("Zombie: Flechas de direccion", True, rojo)
ventana.blit(zzombie, (300,280))

rec = fuente.render("V: reiniciar", True, naranja)
ventana.blit(rec, (350,330))

espacio = fuente.render("Espacio: disparar", True, naranja)
ventana.blit(espacio, (300,380))



pygame.display.update()

#Imagenes
#Fondo
wall = pygame.image.load("img/juego-autobus-londres.jpg")
x,y = 0,0


#Tio
tioizq = pygame.image.load("img/tioizq.png")
xt,yt = 35,310

tiode = pygame.image.load("img/tiode.png")
xt,yt = 35,310

ventana.blit(tiode, (108,275))
pygame.display.update()

tioar = pygame.image.load("img/tioar.png")
xt,yt = 35,310

tioab = pygame.image.load("img/tioab.png")
xt,yt = 35,310

recarga = pygame.image.load("img/tioar.png")
xt,yt = 35,310

#Muerte
m1 = pygame.image.load("img/m1.png")
xz,yz = 35,310

m2 = pygame.image.load("img/m2.png")
xz,yz = 35,310

m3 = pygame.image.load("img/m3.png")
xz,yz = 35,310

#Rayo
rayode = pygame.image.load("img/rayode.png")
xt,yt = 35,310

rayoizq = pygame.image.load("img/rayoizq.png")
xt,yt = 35,310

rayoar = pygame.image.load("img/rayoar.png")
xt,yt = 35,310

rayoab = pygame.image.load("img/rayoab.png")
xt,yt = 35,310

tios = tiode

#Zombie
zombieizq = pygame.image.load("img/zombieizq.png")
xz,yz = 650,310

zombiede = pygame.image.load("img/zombiede.png")
xz,yz = 650,310

ventana.blit(zombiede, (264,275))
pygame.display.update()

zombies = zombieizq


#Bucle de eventos
while True:
	for event in pygame.event.get():
		if event.type == pygame.QUIT:
			pygame.quit()
			sys.exit()
		if event.type == pygame.KEYDOWN :
			
#Direccion tio			
			if event.key == pygame.K_a:
				ventana.blit(wall, [0,0])
				pygame.display.flip()
				xt = xt-11
				ventana.blit(tios, (xt,yt))
				pygame.display.flip()
				ventana.blit(zombies, (xz,yz))
				pygame.display.flip()
				estado = 1
				tios = tioizq
			if event.key == pygame.K_d :
				ventana.blit(wall, [0,0])
				pygame.display.flip()
				xt = xt+11
				ventana.blit(tios, (xt,yt))
				pygame.display.flip()
				ventana.blit(zombies, (xz,yz))
				pygame.display.flip()
				estado = 2
				tios = tiode
			if event.key == pygame.K_w:
				ventana.blit(wall, [0,0])
				pygame.display.flip()
				yt = yt-11
				ventana.blit(tios, (xt,yt))
				pygame.display.flip()
				ventana.blit(zombies, (xz,yz))
				pygame.display.flip()
				estado = 3
				tios = tioar
			if event.key == pygame.K_s:
				ventana.blit(wall, [0,0])
				pygame.display.flip()
				yt = yt+11
				ventana.blit(tios, (xt,yt))
				pygame.display.flip()
				ventana.blit(zombies, (xz,yz))
				pygame.display.flip()
				estado =4
				tios = tioab

#Direccion Zombie					
			if event.key == pygame.K_LEFT:
				zombies = zombieizq
				ventana.blit(wall, [0,0])
				pygame.display.flip()
				pygame.display.update()
				xz = xz-9
				ventana.blit(zombies, (xz,yz))
				pygame.display.flip()
				ventana.blit(tios, (xt,yt))
				pygame.display.flip()
				xtm=xt+31
				ytm=yt+40
				if ((xz >= xt and yz >= yt) and (xz <= xtm  and yz <= ytm)):
					ventana.blit(wall, (0,0))
					ventana.blit(zombies, (0,0))
					pygame.display.flip()
					tios = zombies
			if event.key == pygame.K_RIGHT:
				zombies = zombiede
				ventana.blit(wall, [0,0])
				pygame.display.flip()
				xz = xz+9
				ventana.blit(zombies, (xz,yz))
				pygame.display.flip()
				ventana.blit(tios, (xt,yt))
				pygame.display.flip()
				xtm=xt+31
				ytm=yt+40
				if ((xz >= xt and yz >= yt) and (xz <= xtm  and yz <= ytm)):
					ventana.blit(wall, (0,0))
					ventana.blit(zombies, (0,0))
					pygame.display.flip()
					tios = zombies
			
			if event.key == pygame.K_UP:
				ventana.blit(wall, [0,0])
				pygame.display.flip()
				yz = yz-9
				ventana.blit(zombies, (xz,yz))
				pygame.display.flip()
				ventana.blit(tios, (xt,yt))
				pygame.display.flip()
				xtm=xt+31
				ytm=yt+40
				if ((xz >= xt and yz >= yt) and (xz <= xtm  and yz <= ytm)):
					ventana.blit(wall, (0,0))
					ventana.blit(zombies, (0,0))
					pygame.display.flip()
					tios = zombies
			
			if event.key == pygame.K_DOWN:
				ventana.blit(wall, [0,0])
				pygame.display.flip()
				yz = yz+9
				ventana.blit(zombies, (xz,yz))
				pygame.display.flip()
				ventana.blit(tios, (xt,yt))
				pygame.display.flip()
				xtm=xt+31
				ytm=yt+40
				if ((xz >= xt and yz >= yt) and (xz <= xtm  and yz <= ytm)):
					ventana.blit(wall, (0,0))
					ventana.blit(zombies, (0,0))
					pygame.display.flip()
					tios = zombies

#Recargar			
			if event.key == pygame.K_r:
				ventana.blit(wall, [0,0])
				pygame.display.flip()
				yz = yz
				ventana.blit(zombies, (xz,yz))
				pygame.display.flip()
				ventana.blit(recarga, (xt,yt))
				pygame.display.flip()

#Reiniciar				
			if event.key == pygame.K_v:
				tios = tiode
				zombies = zombieizq
				ventana.blit(wall, [0,0])
				pygame.display.flip()
				ventana.blit(zombies, (650,310))
				pygame.display.flip()
				ventana.blit(tios, (35,310))
				pygame.display.flip()
				xt=35
				yt=310
				xz=650
				yz=310
				
#Direccion disparo:				
			if (event.key == pygame.K_SPACE and estado == 2):
				c = xt+30
				v = yt+17
				shot = pygame.mixer.music.play()
				for i in range(0,10):
					ventana.blit(rayode, (c,v))
					pygame.display.flip()
					time.sleep(0.05)
					c = c+20
					xm = xz+35
					ym = yz+42
					if ((c >= xz and v >= yz) and (c <= xm  and v <= ym)):
							ventana.blit(m1, (xz,yz))
							pygame.display.flip()
							
							ventana.blit(wall, (0,0))
							pygame.display.flip()
							ventana.blit(tios, (xt,yt))
							pygame.display.flip()
							time.sleep(0.8)
							ventana.blit(m2, (xz,yz))
							pygame.display.flip()
							
							ventana.blit(wall, (0,0))
							pygame.display.flip()
							ventana.blit(tios, (xt,yt))
							pygame.display.flip()
							time.sleep(0.8)
							ventana.blit(m3, (xz,yz))
							pygame.display.flip()
							
							ventana.blit(wall, (0,0))
							pygame.display.flip()
							ventana.blit(tios, (xt,yt))
							ventana.blit(m3, (xz,yz))
							pygame.display.flip()
							zombies=m3
					
			if (event.key == pygame.K_SPACE and estado == 1):
				c = xt-20
				v = yt+17
				shot = pygame.mixer.music.play()
				for i in range(0,10):
						ventana.blit(rayoizq, (c,v))
						pygame.display.flip()
						time.sleep(0.05)
						c = c-20
						xm = xz+35
						ym = yz+42
						if ((c >= xz and v >= yz) and (c <= xm  and v <= ym)):
							ventana.blit(m1, (xz,yz))
							pygame.display.flip()
							
							ventana.blit(wall, (0,0))
							pygame.display.flip()
							ventana.blit(tios, (xt,yt))
							pygame.display.flip()
							time.sleep(0.8)
							ventana.blit(m2, (xz,yz))
							pygame.display.flip()
							
							ventana.blit(wall, (0,0))
							pygame.display.flip()
							ventana.blit(tios, (xt,yt))
							pygame.display.flip()
							time.sleep(0.8)
							ventana.blit(m3, (xz,yz))
							pygame.display.flip()
							
							ventana.blit(wall, (0,0))
							pygame.display.flip()
							ventana.blit(tios, (xt,yt))
							ventana.blit(m3, (xz,yz))
							pygame.display.flip()
							zombies=m3
							
						
			if (event.key == pygame.K_SPACE and estado == 3):
				c = xt+17
				v = yt-21
				shot = pygame.mixer.music.play()
				for i in range(0,10):
						ventana.blit(rayoar, (c,v))
						pygame.display.flip()
						time.sleep(0.05)
						v = v-20
						xm = xz+35
						ym = yz+42
						if ((c >= xz and v >= yz) and (c <= xm  and v <= ym)):
							ventana.blit(m1, (xz,yz))
							pygame.display.flip()
							
							ventana.blit(wall, (0,0))
							pygame.display.flip()
							ventana.blit(tios, (xt,yt))
							pygame.display.flip()
							time.sleep(0.8)
							ventana.blit(m2, (xz,yz))
							pygame.display.flip()
							
							ventana.blit(wall, (0,0))
							pygame.display.flip()
							ventana.blit(tios, (xt,yt))
							pygame.display.flip()
							time.sleep(0.8)
							ventana.blit(m3, (xz,yz))
							pygame.display.flip()
							
							ventana.blit(wall, (0,0))
							pygame.display.flip()
							ventana.blit(tios, (xt,yt))
							ventana.blit(m3, (xz,yz))
							pygame.display.flip()
							zombies=m3
						
						
			if (event.key == pygame.K_SPACE and estado == 4):
				c = xt+9
				v = yt+40
				shot = pygame.mixer.music.play()
				for i in range(0,10):
						ventana.blit(rayoab, (c,v))
						pygame.display.flip()
						time.sleep(0.05)
						v = v+20
						xm = xz+35
						ym = yz+42
						if ((c >= xz and v >= yz) and (c <= xm  and v <= ym)):
							ventana.blit(m1, (xz,yz))
							pygame.display.flip()
							
							ventana.blit(wall, (0,0))
							pygame.display.flip()
							ventana.blit(tios, (xt,yt))
							pygame.display.flip()
							time.sleep(0.8)
							ventana.blit(m2, (xz,yz))
							pygame.display.flip()
							
							ventana.blit(wall, (0,0))
							pygame.display.flip()
							ventana.blit(tios, (xt,yt))
							pygame.display.flip()
							time.sleep(0.8)
							ventana.blit(m3, (xz,yz))
							pygame.display.flip()
							
							ventana.blit(wall, (0,0))
							pygame.display.flip()
							ventana.blit(tios, (xt,yt))
							ventana.blit(m3, (xz,yz))
							pygame.display.flip()
							zombies=m3
#Final juego
	if tios==zombies:
				time.sleep(2)
				ventana.blit(wall, [0,0])
				pygame.display.flip()
				ventana.blit(zombies, (xz,yz))
				pygame.display.flip()
				ventana.blit(tios, (xt,yt))
				pygame.display.flip()
				time.sleep(0)
				ventana.blit(wall, [0,0])
				pygame.display.flip()
				ventana.blit(zombieizq, (650,310))
				pygame.display.flip()
				ventana.blit(zombies, (35,310))
				pygame.display.flip()
				tios = tiode
				xt,yt = 35,310
				xz,yz = 650,310
	if zombies==m3:
				time.sleep(2)
				ventana.blit(wall, [0,0])
				pygame.display.flip()
				ventana.blit(zombies, (xz,yz))
				pygame.display.flip()
				ventana.blit(tios, (xt,yt))
				pygame.display.flip()
				pygame.display.update()
				time.sleep(1)
				ventana.blit(wall, [0,0])
				pygame.display.flip()
				ventana.blit(zombieizq, (650,310))
				pygame.display.flip()
				ventana.blit(tiode, (35,310))
				pygame.display.flip()
				tios = tiode
				zombies = zombieizq
				xt,yt = 35,310
				xz,yz = 650,310
 



